<?php

namespace App\Api\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class Authenticate
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = 'api')
    {
//        \Log::info('INTO'.$request->getRequestUri());
        if($request->input('callback')){
            //过期则重新生成，并获取
            if(empty(session()->getId())){
                session()->regenerate();
            }
            else{
//                &&$request->SID==session()->getId()
                if($request->SID!=null){
                    session()->setId($request->SID);
                }
//                else{
//                    session()->flush();
//                    session()->regenerate();
//                }
                return $next($request);
            }
        }
    }
}
